#include<iostream>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/ipc.h>
#include<string>
#include<stdlib.h>
#include<time.h>
#include<unistd.h>
#include<string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include"log.hpp"
#include <stdio.h>
#include <fcntl.h>

using namespace std;


const string Path="/home/xiaoli";
const key_t key=0x6666;

Log log;

key_t GetKey()
{
  key_t id=ftok(Path.c_str(),key);
  if (id<0)
  {
    log(Fatal,"ftok error:%s",strerror(errno));
    exit(-1);
  }

log(Normal,"getkey success:0x%x",id);
 return id; 
}

int ShareMem(int flag)
{
  int mem=shmget(GetKey(),4096,flag);
  if(mem<0)
  {
    log(Fatal,"Shmget error:%s",strerror(errno));
    exit(-2);
  }
  log(Normal,"sucess id:%d",mem);
  return mem;
}
int CreateShmid()
{
 return  ShareMem(IPC_CREAT|IPC_EXCL|0666);
}
int GetShm()
{
  return ShareMem(IPC_CREAT);
}

#define PATH "./myfifo"
#define mode 0666

class Init
{
  public:
  Init()
  {
    
     fd=mkfifo(PATH,mode);
    if(fd<0)
    {
      log(Fatal,"FIFO ALREADY DONE:%s",strerror(errno));
      exit(-1);
    }
  }

  ~Init()
  {
    close(fd);
  }
  private:
  int fd;
};
